<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ContactsController
 *
 * @author pohnean
 */
class ContactsController extends PsController {

	public $defaultAction = 'index';
	public $layout = 'manage';

	public function accessRules() {
		return CMap::mergeArray(array(
					array('allow',
						'roles' => array('ManageModule.Contacts'),
					),
						), parent::accessRules());
	}

	public function actionIndex() {
		$agency = $this->loadAgency();

		if ($agency->settings == null) {
			$agency->settings = array();
		}

		if (!empty($_POST['AgencySetting'])) {
			foreach ($_POST['AgencySetting'] as $key => $value) {
				$agency->setSetting($key, $value);
			}
			

			if ($agency->save(true, array('settings'))) {
				PsSystemMessage::add('Your changes have been saved.', 'success');
				$this->refresh();
			}
		}

		$data = array();
		$data['agency'] = $agency;
		$this->render('index', $data);
	}

	public function loadAgency() {
		return Yii::app()->user->model->agency;
	}

}

?>
